package cn.middle.remote.util;

import cn.middle.remote.message.BaseSignal;
import cn.middle.remote.message.SignalHelper;

@SuppressWarnings("rawtypes")
public class PrioritySort<T extends BaseSignal> implements Comparable<PrioritySort>{
	
	/**
	 * 最高级
	 */
	private static final int OPTIMAL_PRIORITY = 1;
	
	/**
	 * 普通级
	 */
	private static final int ORDINARY_PRIORITY = 5;
	
	/**
	 * 最低级
	 */
	private static final int  MINIMUM_PRIORITY = 10;
	
	/**
	 * 默认普通级
	 */
	private int priority = ORDINARY_PRIORITY ;
	
	private T value;
	
	
	public PrioritySort(T t) {
		this.value = t;
		setPriority();
	}
	
	public T getValue() {
		return this.value;
	}
	
	private void setPriority() {
		if(
				value.getMessageType() == SignalHelper.LOGIN_RESULT 
				|| value.getMessageType() == SignalHelper.CALL
				|| value.getMessageType() == SignalHelper.REPLY
				|| value.getMessageType() == SignalHelper.EDGE_REPLY
				) { //登陆信息返回、调用、调用回复、边缘服务回复 为最高级别
			this.priority = OPTIMAL_PRIORITY;
		}else if(value.getMessageType() == SignalHelper.EVENT_REPORT) {
			//事件上报优先级别最低
			this.priority = MINIMUM_PRIORITY;
		}
		//其余默认为普通级别
	}

	@Override
	public int compareTo(PrioritySort o) {
		return this.priority - o.priority;
	}

}
